// 推荐的请求
import jsonp from 'common/js/jsonp'
import axios from 'axios'
import {
  CommendParam,
  CommendOptions
} from './config'

// 请求banner数据
export function getRecommend() {
  let url = 'https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg'
  const data = Object.assign({}, CommendParam, {
    // 未登录
    uin: 0,
    // 移动端
    platform: 'h5',
    needNewCode: 1
  })
  return jsonp(url, data, CommendOptions)
}

// 请求 歌单
export function getDisList() {
  let url = 'https://u.y.qq.com/cgi-bin/musicu.fcg'
  let obj = {
    'comm': {
      'ct': 24
    },
    'category': {
      'method': 'get_hot_category',
      'param': {
        'qq': ''
      },
      'module': 'music.web_category_svr'
    },
    'recomPlaylist': {
      'method': 'get_hot_recommend',
      'param': {
        'async': 1,
        'cmd': 2
      },
      'module': 'playlist.HotRecommendServer'
    },
    'playlist': {
      'method': 'get_playlist_by_category',
      'param': {
        'id': 8,
        'curPage': 1,
        'size': 40,
        'order': 5,
        'titleid': 8
      },
      'module': 'playlist.PlayListPlazaServer'
    },
    'new_song': {
      'module': 'QQMusic.MusichallServer',
      'method': 'GetNewSong',
      'param': {
        'type': 0
      }
    },
    'new_album': {
      'module': 'music.web_album_library',
      'method': 'get_album_by_tags',
      'param': {
        'area': 1,
        'company': -1,
        'genre': -1,
        'type': -1,
        'year': -1,
        'sort': 2,
        'get_tags': 1,
        'sin': 0,
        'num': 40,
        'click_albumid': 0
      }
    },
    'toplist': {
      'module': 'music.web_toplist_svr',
      'method': 'get_toplist_index',
      'param': {}
    },
    'focus': {
      'module': 'QQMusic.MusichallServer',
      'method': 'GetFocus',
      'param': {}
    }
  }
  const data = Object.assign({}, CommendParam, {
    callback: 'recom123',
    loginUin: 0,
    hostUin: 0,
    platform: 'yqq',
    needNewCode: 0,
    data: JSON.stringify(obj)
  })
  let DisListOptions = Object.assign({}, {
    // 前缀
    // prefix: 'recom',
    // 回调名称
    name: 'recom123'
  }, CommendOptions)
  return jsonp(url, data, DisListOptions)
}

// 后台请求模拟 返回本地数据
export function getDownload() {
  const data = Object.assign({}, CommendParam, {
    loginUin: 0,
    hostUin: 0,
    platform: 'h5',
    needNewCode: 1,
    format: 'json'
  })
  return axios.get('/api/getDownload', {
    params: data
  }).then((res) => {
    return Promise.resolve(res.data)
  })
}

// 歌单数据
export function getSongSheet(mid) {
  const url = 'api/sheet'

  const data = Object.assign({}, CommendParam, {
    loginUin: 0,
    hostUin: 0,
    needNewCode: 0,
    pcachetime: +new Date(),
    disstid: mid,
    format: 'json',
    platform: 'yqq.json',
    type: 1,
    json: 1,
    utf8: 1
  })

  return axios.get(url, {
    params: data
  }).then((res) => {
    return Promise.resolve(res.data)
  })
}
